<br>
<form id="mainform" name='frm' method=post action="">
   	<div>
		<div id="toolbar-button" style="float: right">
			<div class="item" onclick="add()" name="addButton" id="addButton" title="Add new Price">
				<div id="addnew-global-button"></div>
			</div>
		</div>
	</div>
    <table style="margin-top: 10px;clear: both" border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <thead>
            <tr>
                <th class="table-header-repeat line-left" width="30%" style="text-align: center"><a>MINIMUM(days)</a></th>
				<th class="table-header-repeat line-left" width="30%" style="text-align: center"><a>MAXIMUM(days)</a></th>
				<th class="table-header-repeat line-left" width="30%" style="text-align: center"><a>PRICE</a></th>
				<th class="table-header-repeat line-left" width="" style="text-align: center"><a>ACTION</a></th>
            </tr>
        </thead>
        <tfoot>
        </tfoot>
        <tbody>
            <?php
			if (count($this->data) == 0) {
				echo "<tr id='no-data'><td colspan=6>There is not any data</td></tr>";
			} 
			foreach ($this->data as $item) {
			?>
            <tr id="<?= 'row'.$item['PRICEID']?>">
				<td> 
					<div class="price-configuration-list-data">
                        <?=$item['MINDAYNUMBER'];?>
					</div>
                </td>
				<td>
					<div class="price-configuration-list-data">
                        <?=$item['MAXDAYNUMBER'];?>
					</div>
                </td>
                <td>
					<div class="price-configuration-list-data">
                        <?=$item['PRICE'];?>
					</div>
                </td>
				<td style="padding-left: 0px">
					<div>
						<select id="<?php echo 'actionbox'.$item['PRICEID'] ?>" name="<?php echo 'actionbox'.$item['PRICEID'] ?>" onchange="chooseAction(<?=$item['PRICEID'] ?>)">
							<option value="0" >Choose an Action</option>
							<option value="<?=$item['PRICEID'] ?>" >Edit</option>
							<option value="<?=$item['PRICEID'] ?>" >Delete</option>
						</select>
					</div>
                </td>
			</tr>
			<? } ?>
        </tbody>
    </table>

</form>
<div id="add-price-dialog" title="Add Price"> 
</div>
<script type="text/javascript">
	function chooseAction(itemID){
		text = $("#actionbox"+itemID+ " option:selected").text();
		if(text == 'Edit'){
			edit(itemID);
		}else if(text == "Delete"){
			deleteItem(itemID);
		}
    }
	
	function deleteItem(itemID){
		check = confirm("Do you want to delete this user?");
		if(check){
			$.ajax({
				url: "/admin/price/delete",
				type: "POST",
				data: {itemID : itemID},
				dataType: "text",
				success: function(data) {
					var result = $.trim(data);
					if(result == 'successful'){
						$('#row' + itemID).fadeOut('slow');
						$('#row' + itemID).remove();
					} else {
						alert(result);
					}
				}
			});
		}
	}
	
	function add(){
		$('#add-price-dialog').dialog({
			modal: true,
			width: 475,
			height: 180,
			resizable: false,
			buttons : {
				"Save": function(){ save();}
			}
		});
		$.ajax({
		url: '/admin/price/input',
		type: 'POST',
		success: function(data) {
				if(data){
					$('#add-price-dialog').html(data);
				}
			}
		});
	}
	
	function edit(itemID){
		$('#add-price-dialog').dialog({
			modal: true,
			width: 475,
			height: 180,
			resizable: false,
			buttons : {
				"Save": function(){ save();}
			}
		});
		$('#actionbox' + itemID + " option[value ='0']").attr('selected','');
		$.ajax({
		url: '/admin/price/input',
		type: 'POST',
		data: {itemID : itemID}, 
		success: function(data) {
				if(data){
					$('#add-price-dialog').html(data);
				}
			}
		});
	}
</script>